package test.YTool;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

// http://bbs.csdn.net/topics/370213517
// 方便的读文件类
public class YReadFile {
	public void YReadFile(){
		
	}
	
	/*
	 * 文件不存在返回 null
	 */
	static public String ReadAllToString(String filePath) throws IOException{
        File file = new File(filePath);
        FileReader reader;
        try{
        	reader = new FileReader(file);
        }catch(FileNotFoundException e){
        	e.printStackTrace();
        	return null;
        }
        
        int fileLen = (int)file.length();
        if( fileLen<=0 ){
        	reader.close();
        	return "";
        }
        char[] chars = new char[fileLen];
        reader.read(chars);
        
        String txt = String.valueOf(chars);
        reader.close();
        return txt;
	};
}
